<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        /*字面量创建对象*/
        var obj={};
        obj={
            name: '张三',
            age: 18,
            sex: '男',
            sayHi: function (){           //对象里面的函数 是方法

                console.log('大家好')

                return 'sayHi被调用了';
            }
        };

        obj.sayHi()
        console.log(obj.sayHi())

        console.log(obj['name']);
        console.log(obj.age);


        /* new Object 创建对象  */
        var obj2=new Object();
        obj2.name= '张三疯';
        obj2.age= 20;
        obj2.sayHi=function (){           //对象里面的函数 是方法

            console.log('大家好')

            return '对象张三疯被调用了';
        };


        console.log(obj2.sayHi())


        /*构造方法创建对象 */

        function Star(name,age){
            this.name=name;
            this.age=age;
            this.sing=function (ge){
                console.log(name+"唱"+ge)
            }
        }

        var one=new Star('张学友',18);

        for(var k in one ){
            console.log(1111)
            console.log(k);             //属性名字
            console.log(one[k])         //属性值
        }

        console.log(one)
        console.log(typeof one)    //object
        console.log(one.name)

        one.sing('李香兰')





    </script>
</head>
<body>

</body>
</html>